//
//  main.cpp
//  拷贝构造函数
//
//  Created by linjinzhu on 2017/7/11.
//  Copyright © 2017年 baidu. All rights reserved.
//

#include <iostream>

using namespace std;

class Line {
public:
    double getLength();

    Line(double len); // 简单构造函数
    Line(const Line &line); // 拷贝构造函数
    ~Line();// 析构函数

private:
    double *ptr;
};

double Line::getLength() {
    return *ptr;
}

Line::Line (double len) {
    ptr = new double;
    *ptr = len;

    cout << "normal constructor" << endl;
}

Line::Line(const Line &line) {
    ptr = new double;
    *ptr = *line.ptr;
    cout << "copy constructor" << endl;
}

Line::~Line() {
    delete ptr;
    cout << "pointer deleted." << endl;
}

int main(int argc, const char * argv[]) {

    Line line1(1);
    cout << line1.getLength() << endl;

    Line line2 = line1;
    cout << line2.getLength() << endl;




    return 0;
}
